package client;

import common.LoginPassword;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: Igor Demidov
 * Date: 24.02.13
 * Time: 11:39
 */
public class LoginPageGUI {

    private JTextField loginField;
    private JPanel panel1;
    private JPasswordField passwordField;
    private JButton doneButton;

    LoginPageGUI(final MainClient client) {
        final JFrame frame = new JFrame("Login Page");
        frame.setContentPane(this.panel1);
        frame.pack();
        frame.setVisible(true);
        doneButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String login = loginField.getText();
                String password = new String(passwordField.getPassword());
                try {
                    if (client.doLogin(new LoginPassword(login, password))) {
                        frame.setVisible(false);
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                } catch (ClassNotFoundException e1) {
                    e1.printStackTrace();
                }
            }
        });
    }
}
